//
//  YILogin.m
//  一点互助
//
//  Created by rimi on 16/8/20.
//  Copyright © 2016年 shen. All rights reserved.
//

#import "YILogin.h"
#import "YIRegister.h"
@interface YILogin ()

@end

@implementation YILogin

- (void)viewDidLoad {
    [super viewDidLoad];
       self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1];
       [self headView];
       [self setuserNameTextField];
       [self setPassWordTextField];
       [self setLoginBtn];
}

-(void)headView{
       UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kBaseWidth, 64)];
       headView.backgroundColor = HEADER_COLOR;
       [self.view addSubview:headView];
       
       UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
       //设置图片
       UIImage *imageForButton = [UIImage imageNamed:@"个人中心-left"];
       [backBtn setImage:imageForButton forState:UIControlStateNormal];
       //设置文字
       NSString *buttonTitleStr = @"登录";
       [backBtn setTitle:buttonTitleStr forState:UIControlStateNormal];
       backBtn.titleLabel.font = [UIFont systemFontOfSize:15];
       [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
       backBtn.frame = CGRectMake(10, 30 , 60, 20);
       [backBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
       backBtn.tag = 100;
       [headView addSubview:backBtn];
       
       UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
       registerBtn.frame = CGRectMake(kBaseWidth - 60, 30 , 40, 20);
       registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
       [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
       [headView addSubview:registerBtn];
//       [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//              make.right.equalTo(headView.mas_right).offset(10);
//              make.top.equalTo(headView.mas_top).offset(30);
//              make.width.mas_equalTo(44);
//              make.height.height.mas_equalTo(44);
//       }];
       [registerBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
       registerBtn.tag = 101;
       
}
-(void)click:(UIButton *)btn{
       if (btn.tag == 100) {
              [self dismissViewControllerAnimated:YES completion:nil];
       }
       if (btn.tag == 101) {
              YIRegister *registerVC = [[YIRegister alloc]init];
              registerVC.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
              [self presentViewController:registerVC animated:YES completion:nil];
       }
       
}

-(void)setuserNameTextField{

       UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, kScreenWidth, 50)];
       backView.backgroundColor = [UIColor whiteColor];
       [self.view addSubview:backView];
       
       UIImageView *leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 30, 30)];
       leftImage.image = [UIImage imageNamed:@"登录注册-手机"];
       [backView addSubview:leftImage];
       
       UITextField *userName = [[UITextField alloc]initWithFrame:CGRectMake(70, 10, kScreenWidth - 80, 30)];
           userName.placeholder = @"请输入手机号";
       userName.font = [UIFont systemFontOfSize:15];
       userName.backgroundColor = [UIColor whiteColor];
       userName.clearButtonMode = UITextFieldViewModeAlways;
       [backView addSubview:userName];
       
       UILabel *userNameLeft = [[UILabel alloc]initWithFrame:CGRectMake(60, 18, 1, 13)];
       userNameLeft.backgroundColor = [UIColor grayColor];
       [backView addSubview:userNameLeft];
       
       
}

-(void)setPassWordTextField{
       UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 122, kScreenWidth, 50)];
       backView.backgroundColor = [UIColor whiteColor];
       [self.view addSubview:backView];
       
       UIImageView *rightImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 30, 30)];
       rightImage.image = [UIImage imageNamed:@"登录注册-钥匙"];
       [backView addSubview:rightImage];
       
       UITextField *passWord = [[UITextField alloc]initWithFrame:CGRectMake(70, 10, kScreenWidth - 80, 30)];
       passWord.secureTextEntry = YES;
       passWord.clearButtonMode = UITextFieldViewModeAlways;
       passWord.placeholder = @"请输入密码";
       passWord.font = [UIFont systemFontOfSize:15];
       passWord.backgroundColor = [UIColor whiteColor];
       [backView addSubview:passWord];
       
       UILabel *passWordLeft = [[UILabel alloc]initWithFrame:CGRectMake(60, 18, 1, 13)];
       passWordLeft.backgroundColor = [UIColor grayColor];
       [backView addSubview:passWordLeft];
}

-(void)setLoginBtn{
       UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
       loginBtn.frame = CGRectMake(kScreenWidth / 2 - (kScreenWidth - 80)/2, 200, kScreenWidth - 80, 50);
       loginBtn.layer.cornerRadius = 5;
       loginBtn.backgroundColor = HEADER_COLOR;
       [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
       loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
       [loginBtn setTintColor:[UIColor whiteColor]];
       [self.view addSubview:loginBtn];
                         
}
@end
